Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
Cannot access "audio" before initialization in js problem at line 2

Made a clock and alarm a while back and was going to maybe add some more and now the clock is no longer displaying. Problem possibly around line 2 (Learning to code I know its probably something simple) The error code I get back is just the initialization of the audio saying that it is unable to access even though it's in the same file

    '''

const display = document.getElementById('clock');
const audio = new audio('finAlarm.wav');
audio.loop = true;
let alarmTime = null;
let alarmTimeout = null;

function updateTime() {
const date = new Date();

const hour = formatTime(date.getHours());
const minutes = formatTime(date.getMinutes());
const seconds = formatTime(date.getSeconds());



display.innerText=`${hour} : ${minutes} : ${seconds}`
}

function formatTime(time) {
if ( time < 10 ) {
    return '0' + time;
}
return time;
}

function setAlarmTime(value) {
alarmTime = value;
}

function setAlarm() {
if(alarmTime) {
    const current = new Date();
    const timeToAlarm = new Date(alarmTime);

    if (timeToAlarm > current) {
        const timeout = timeToAlarm.getTime() - current.getTime();
        alarmTimeout = setTimeout(() => audio.play(), timeout);
        alert('Alarm set');
    }
}
}

function clearAlarm() {
var name = prompt("are you up?>:)")
if (name ==null || name=="") {
txt = "incorrect >:(|)"
} else {
    audio.pause();
    audio.currentTime = 0;
    alert('Alarm Stopped')
     }
     alert(txt);
     audio.pause();
audio.currentTime = 0;
if (alarmTimeout) {
    clearTimeout(alarmTimeout);
    alert('Alarm Stopped');
}
}

setInterval(updateTime, 1000);

    '''
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda